package com.lei.yohuo001java;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.blankj.utilcode.util.SPUtils;
import com.lei.mvp_retrofitlibrary.http.bean.LoginBean;
import com.lei.mvp_retrofitlibrary.mvp.view.BaseActivity;
import com.lei.yohuo001java.contract.ShopContract;
import com.lei.yohuo001java.model.ShopModel;
import com.lei.yohuo001java.presenter.ShopPresenter;

public class LoginActivity extends BaseActivity<ShopPresenter> implements ShopContract.LoginView {
    private EditText actLogEtName;
    private EditText actLogEtPwd;
    private Button actLogBtLogin;
    private Button actLogBtRegister;

    @Override
    public int bindlayout() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {
        actLogEtName = (EditText) findViewById(R.id.act_log_et_name);
        actLogEtPwd = (EditText) findViewById(R.id.act_log_et_pwd);
        actLogBtLogin = (Button) findViewById(R.id.act_log_bt_login);
        actLogBtRegister = (Button) findViewById(R.id.act_log_bt_register);
        mPrensenter = new ShopPresenter(new ShopModel(),this);
    }

    @Override
    public void initData() {
        actLogBtRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(LoginActivity.this,RegisterActivity.class));
            }
        });
        actLogBtLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showToast("点击了");
                String name = actLogEtName.getText().toString().trim();
                String pwd = actLogEtPwd.getText().toString().trim();
                mPrensenter.initlogin(name,pwd);
            }
        });
    }

    @Override
    public void showLayout() {

    }

    @Override
    public void hideLayout() {

    }

    @Override
    public void showToast(String msg) {
        Toast.makeText(this, ""+msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void logindata(LoginBean loginBean) {
        if (loginBean.getCode()==200){
            showToast("登陆成功");
            SPUtils.getInstance().put("log",true);
            finish();
        }else {
            showToast("登录失败"+loginBean.getMsg());
        }
    }
}
